package com.tiku.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.tiku.entity.LoginUser;
import com.tiku.entity.UserInfo;
import com.tiku.entity.entityInterface;
import com.tiku.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class AuthenticationImpl implements UserDetailsService {



    @Autowired
    private UserInfoService userInfoService;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        entityInterface info=null;

        //普通用户
        info = userInfoService.getOne(new LambdaQueryWrapper<UserInfo>(UserInfo.class).eq(UserInfo::getUserPhone, username));




        if (Objects.isNull(info)){
            throw new BadCredentialsException("用户不存在！");
        }

        return new LoginUser(info);
    }
}
